// Package user 模型
package user

import (
	// "gitee.com/sweetsunnyflower/carpooling-server-go/pkg/logger"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models/driver"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models/passenger"

	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/database"
)

// User 用户模型,omitempty:空字段不返回
type User struct {
	models.BaseModel

	Avatar   string `json:"avatar"`
	Name     string `json:"name"` // 姓名
	OpenId   string `json:"open_id"`
	Email    string `json:"email"`
	Phone    string `json:"phone"`
	Password string `json:"-"`
	Gender   uint8  `gorm:"comment:性别 2:女,1:男;default:0;" db:"gender" json:"gender"`

	Driver    *driver.Driver       `json:"driver"`
	Passenger *passenger.Passenger `json:"passenger"`

	models.CommonTimestampsField
}

func (user *User) Create() {
	database.DB.Create(&user)
}

func (user *User) Save() (rowsAffected int64) {
	result := database.DB.Save(&user)
	return result.RowsAffected
}

func (user *User) Delete() (rowsAffected int64) {
	result := database.DB.Delete(&user)
	return result.RowsAffected
}
